/**
 * Created by Administrator on 2017-02-08.
 */


const spider = require('./spider')
const filesys = require('./filesys')
const fs = require('fs');


spider.get('http://www.phome.net/doc/manual/template/html/img/indextemp1.jpg',false).then((buf) => {
    let filePath = 'E:\\img\\indextemp1.jpg';
    let fileFolder = filePath.substring(0,filePath.lastIndexOf('\\'));
    //console.log(filePath,'====',fileFolder)
    if(!fs.existsSync(fileFolder))
        filesys.mkdirsSync(fileFolder, 777);
    fs.open(filePath, 'w', (err, fd) => {
        if (err) throw err;
        fs.writeFile(filePath, buf, {
            encoding: null
        }, (err) => {
            if (err) throw err;
            console.log(filePath + ' saved!');
        })
    })
});